package com.gupaoedu.task.pattern.singleton.lazy;
/**
 * @author djl
 * @Title: LazyDoubleCheckSingleton
 * @Description: TODO
 * @date 2019/3/29
 */
public class LazyDoubleCheckSingleton {
    //加上volatile关键字，使的所有线程都能看到内存状态，保证内存的可见性。
    private volatile static LazyDoubleCheckSingleton lazy = null;
    private LazyDoubleCheckSingleton(){}
    public static LazyDoubleCheckSingleton getInstance(){
        if(lazy == null){
            synchronized (LazyDoubleCheckSingleton.class){
                if(lazy == null){
                    lazy = new LazyDoubleCheckSingleton();
                    //1.分配内存给这个对象
                    //2.初始化对象
                    //3.设置lazy指向刚分配的内存地址
                    //4.初次访问对象
                }
            }
        }
        return lazy;
    }
}
